/*
*

	bulb 封装方法
	@author: taco
	@Date: 2022/6/17
	@Time: 13:26

*
*/
package utils

import (
	"github.com/sirupsen/logrus"
)

// 设备类型
const (
	DeviceTypeInvalid = iota
	DeviceTypeBulbColor
	DeviceTypeBulbWarnCold
	DeviceTypeSweeper
	DeviceTypeAlarm
	DeviceTypeIPC
	DeviceDML
	DeviceTypeBulbStrip
)

const (
	Attr_set    = "thing.attribute.set"
	Attr_adjust = "thing.attribute.adjust"
)

var SwitchMap = map[string]int32{
	"关":  0,
	"开":  1,
	"继续": 1,
	"暂停": 2,
	"结束": 2,
}

var SweeperSwitchReply = map[string]string{
	"关":  "已经关了",
	"开":  "开始清扫",
	"继续": "正在清扫",
	"暂停": "已经暂停",
	"结束": "已经停止",
}

var PowerStateMap = map[int]string{
	0: "关闭",
	1: "开启",
	2: "关闭",
}

var SweeperPowerStaus = map[int]string{
	0: "关",
	1: "开",
	2: "关",
}

type SlotEntities struct {
	Name            string `form:"name" json:"name"`
	StandardValue   string `form:"value" json:"value"`
	IsInquireFailed bool   `form:"is_inquire_failed" json:"is_inquire_failed"`
}

func (dc *DCCtrlEvent) GetDeviceTypeStr() string {
	if dc.DeviceId != "" {
		if dc.DeviceId[:6] == "000014" || dc.DeviceId[:6] == "000013" {
			return "sweeper"
		} else if dc.DeviceId[:6] == "000002" || dc.DeviceId[:6] == "000012" || dc.DeviceId[:6] == "000023" ||
			dc.DeviceId[:6] == "000024" || dc.DeviceId[:6] == "000006" || dc.DeviceId[:6][:6] == "000025" {
			return "light"
		}
	}
	return "None"
}
func (dc *DCCtrlEvent) GetDeviceTypeInt() int32 {
	logrus.Println("device Id = ", dc.DeviceId)
	if dc.DeviceId != "" {
		if dc.DeviceId[:6] == "000014" || dc.DeviceId[:6] == "000013" {
			return DeviceTypeSweeper
		} else if dc.DeviceId[:6] == "000002" || dc.DeviceId[:6] == "000024" {
			return DeviceTypeBulbColor
		} else if dc.DeviceId[:6] == "000012" || dc.DeviceId[:6] == "000006" || dc.DeviceId[:6] == "000025" {
			return DeviceTypeBulbWarnCold
		} else if dc.DeviceId[:6] == "000023" {
			return DeviceTypeBulbStrip
		}
	}
	return 0
}

// DCCtrlEvent bulb from aligenie server
type DCCtrlEvent struct {
	Name                     string //小度的header中的name
	MessageId                string //小度需要的messageId
	Version                  string //小爱
	UserName                 string
	Uuid                     string
	SessionID                string
	Utterance                string //使用者说的话
	SkillID                  string //技能的id
	SkillName                string //技能的名称
	Token                    string //token
	IntentName               string //意图标识
	SlotEntities             SlotEntitiesList
	DBPinCode                string
	IntentId                 int `json:"intentId"`
	Reply                    string
	IsEnd                    bool //是否结束对话（小爱需要）
	OpenUid                  string
	DeviceId                 string  //设备id
	BrightnessValue          float64 //值光照
	IncrementOrD             float64 //增加或者减少rggff
	ColorTemperatureInKelvin int     // 色温
	Hue                      float64
	Saturation               float64
	Brightness               float64
	ModelName                string //模式名称
}

type SlotEntitiesList []SlotEntities

func (arr SlotEntitiesList) GetObjByName(name string) *SlotEntities {
	for _, v := range arr {
		if v.Name == name {
			return &v
		}
	}
	return nil
}

func (arr *SlotEntitiesList) SetObjByName(nameAndValue map[string]string) *SlotEntities {
	for name, value := range nameAndValue {
		*arr = append(*arr, SlotEntities{
			Name:          name,
			StandardValue: value,
		})
	}
	return nil
}

func (arr SlotEntitiesList) GetObjByValue(value string) *SlotEntities {
	for _, v := range arr {
		if v.StandardValue == value {
			return &v
		}
	}
	return nil
}
